package com.bosssoft.hr.train.j2se.collection;/*
 * @Auther:hantianbing
 * @Date:2022/12/2
 * @Description:HashMap练习文档
 */

import com.bosssoft.hr.train.j2se.pojo.entity.User;
import com.bosssoft.hr.train.j2se.util.CreatUser;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName HashMapDemo
 * @Description 练习hashmap所用类
 * @Author hantianbing
 * @Date 2022/12/2 12:44
 **/
@Slf4j
public class HashMapDemo {

    private HashMap<Long, User> userMap = new HashMap<>();

    private int num = 10;

    /**
     * 迭代输出user
     */
    public void printUser(){
        //调用工具创建num个用户
        User[] users = CreatUser.creatUser(num);
        for(User user: users){
            userMap.put(user.getId(), user);
        }
        //迭代遍历
        Set<Map.Entry<Long,User>> setUser=userMap.entrySet();
        if(null==setUser){
            throw new RuntimeException("不存在数据");
        }
        for(Map.Entry<Long, User> entry : setUser){
            log.info(Constraint.LOG_TAG+"{}",entry.getKey().toString()+"####"+entry.getValue());
        }

    }

    public static void main(String[] args) {
        HashMapDemo hashMapDemo = new HashMapDemo();
        hashMapDemo.printUser();
    }
}
